import Vue from 'vue'

import Cookies from 'js-cookie'

import 'normalize.css/normalize.css' // A modern alternative to CSS resets


import App from './App'
import store from './store'
import router from './router'

import '@/icons' // icon
import '@/permission' // permission control
import './utils/error-log' // error log

import * as filters from './filters' // global filters

/**
 * If you don't want to use mock-server
 * you want to use MockJs for mock api
 * you can execute: mockXHR()
 *
 * Currently MockJs will be used in the production environment,
 * please remove it before going online ! ! !
 */
if (process.env.NODE_ENV === 'production') {
  const { mockXHR } = require('../mock')
  mockXHR()
}

// result.type = success, warning, info, error
Vue.prototype.notify = function (result, content, duration){
  this.$notify.closeAll()

  if (content === undefined) {
    content = result.content
  }
  if (duration === undefined) {
    duration = 4000
  }
  let type = result.type;
  if (this.isNull(type)) {
    type = result.success?'success':'error';
  }
  this.$notify({
    title: result.success?'成功':'失败',
    type,
    message: content,
    duration: duration
  });
}

Vue.prototype.isNull = function (str){
  if (str === null || str === undefined || str.length === 0) {
    return true
  }
  return false
}


//复制到粘贴板插件
import VueClipboard from 'vue-clipboard2'
VueClipboard.config.autoSetContainer = true
Vue.use(VueClipboard)

// set ElementUI lang to EN
// Vue.use(ElementUI, { locale })
// 如果想要中文版 element-ui，按如下方式声明
// Vue.use(ElementUI)

import './assets/style.scss'
import './styles/element-variables.scss'
import '@/styles/index.scss' // global css
import 'element-ui/lib/theme-chalk/index.css'
import locale from 'element-ui/lib/locale/lang/zh-CN' // lang i18n
import Element from 'element-ui'
Vue.use(Element, {
  locale,
  size: Cookies.get('size') || 'medium' // set element-ui default size
})


// register global utility filters
Object.keys(filters).forEach(key => {
  Vue.filter(key, filters[key])
})

//全局配置fast dfs file callback uri this.fastDfsCallbackUri
//development
// Vue.prototype.fastDfsCallbackUri = 'http://192.168.110.100:8080/'
//production
Vue.prototype.fastDfsCallbackUri = process.env.VUE_APP_Fastdfs_Callback

import { wgs84togcj02 } from '@/utils/coordsSystem.js'
Vue.filter('wgs2gc', function (value) {
  var bd_lng = parseFloat(value[0])
  var bd_lat = parseFloat(value[1])
  return wgs84togcj02(bd_lng, bd_lat)
})

Vue.filter('bd2gaode', function (value) {
  var bd_lng = parseFloat(value[0])
  var bd_lat = parseFloat(value[1])
  return bd2gaode(bd_lng, bd_lat)
})
function bd2gaode(bd_lng, bd_lat) {
  var X_PI = Math.PI * 3000.0 / 180.0
  var x = bd_lng - 0.0065
  var y = bd_lat - 0.006
  var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * X_PI)
  var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * X_PI)
  var gg_lng = z * Math.cos(theta)
  var gg_lat = z * Math.sin(theta)
  return [gg_lng, gg_lat]
}

Vue.config.productionTip = false

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
})
